From 66798c9b3b9f3d175f23f2cb44295841bbba7f51 Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc" Date: Mon, 7 Dec 2020 23:33:16 -0600 Subject: [PATCH] Log the url map given to templates --- src/pgwui_common/urls.py | 6 ++++++ tests/test_urls.py | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/pgwui_common/urls.py b/src/pgwui_common/urls.py index c87f88c..63ae9cd 100644 --- a/src/pgwui_common/urls.py +++ b/src/pgwui_common/urls.py @@ -22,11 +22,15 @@ '''Expose useful response "variables" to templates ''' +import logging import pyramid.request from .plugin import find_pgwui_components from . import exceptions as ex +# Logging +log = logging.getLogger(__name__) + def route_path(request, page_name, source): '''Return the route path of the page's "source" @@ -113,3 +117,5 @@ def add_urls_setting(config, settings): request.registry = config.registry set_urls(request, urls) settings['pgwui']['urls'] = urls + log.debug('Routing map of route names to url paths which is given' + f' to the templates: {urls}') diff --git a/tests/test_urls.py b/tests/test_urls.py index 9a3c467..1bc4913 100644 --- a/tests/test_urls.py +++ b/tests/test_urls.py @@ -20,6 +20,7 @@ # Karl O. Pinc import pytest +import logging import pyramid.request from pyramid.threadlocal import get_current_request @@ -286,10 +287,11 @@ mock_set_urls = testing.make_mock_fixture( # add_urls_setting() def test_add_urls_setting( - pyramid_request_config, mock_request_blank, mock_set_urls): + caplog, pyramid_request_config, mock_request_blank, mock_set_urls): '''Request.blank() and set_urls() are called, the urls set are put in the pgwui dict in the settings ''' + caplog.set_level(logging.DEBUG) expected_urls = {'key1': 'val1', 'key2': 'val2'} def set_urls(request, urls): @@ -307,3 +309,7 @@ def test_add_urls_setting( mock_request_blank.blank.assert_called_once() mock_set_urls.assert_called_once() assert settings['pgwui']['urls'] == expected_urls + + logs = caplog.record_tuples + assert len(logs) == 1 + assert logs[0][1] == logging.DEBUG -- 2.34.1